﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


namespace lcmyjobs.Web.Controls
{
    public partial class EnterpriseLogin : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["enterprise_name"] != null)
            {
                this.pnl_enterprise_login.Visible = false;
                this.pnl_enterprise_logined.Visible = true;
                this.lbl_enterprise.Text = "欢迎您：" + Session["enterprise_name"].ToString();
            }
            else
            {
                this.pnl_enterprise_login.Visible = true;
                this.pnl_enterprise_logined.Visible = false;
            }
        }

        protected void btn_enLogin_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                string login = this.txtname.Text;
                string pwd = this.txtpass.Text;
                string checkcode = this.txt_code.Text.Trim();
                if (Session["CheckCode"] != null)
                {
                    if (checkcode.ToUpper() == Session["CheckCode"].ToString())
                    {
                        lcmyjobs.BLL.enterprise_basic eb = new BLL.enterprise_basic();
                        int enterprise_bid = 0;
                        pwd = myPublic.GetMd5(pwd);
                        DataSet ds = eb.Check_login(login, pwd, out enterprise_bid);

                        if (enterprise_bid != 0)
                        {
                            Session["enterprise_bid"] = enterprise_bid;

                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                Session["lastlogin"] = ds.Tables[0].Rows[0][0];//上次登陆时间
                                Session["enterprise_name"] = ds.Tables[0].Rows[0][1];//企业名称
                            }

                            this.pnl_enterprise_login.Visible = false;
                            this.pnl_enterprise_logined.Visible = true;

                            this.lbl_enterprise.Text = "欢饮您：" + Session["enterprise_name"].ToString();
                        }
                        else
                            Maticsoft.Common.MessageBox.Show(Page, "用户名或密码不对！");

                    }
                    else
                        Maticsoft.Common.MessageBox.Show(Page, "验证码不对！");
                }
                else
                    Maticsoft.Common.MessageBox.Show(Page, "验证码不对！");

            }
        }
    }
}